By: Adam Li
These functions are here to extract the mat files for the ROIs and faces/vertices of a brain plot. I extract the data from the .mat and convert them to dataframes for easy saving into csv and json format.
The data can be correspondingly read into d3.js using a web server and then used to create interactive brain plots on a web browser.
In [8]:
import os.path
import pandas as pd
from IPython.display import display
import numpy as np
import scipy.io
import h5py
import matplotlib
from matplotlib import *
from matplotlib import pyplot as plt
import itertools
from mpl_toolkits.axes_grid1 import make_axes_locatable
# pretty charting
import seaborn as sns
sns.set_palette('muted')
sns.set_style('darkgrid')
%matplotlib inline
In [37]:
## SET EEGROOTDIR
eegHomeDir = '/Users/adam2392/Documents/MATLAB/Johns Hopkins/NINDS_Rotation/'
eegVolumeDir = '/Volumes/NIL_PASS/'
if os.path.exists(eegVolumeDir):
eegRootDir = eegVolumeDir
elif os.path.exists(eegHomeDir):
eegRootDir = eegHomeDir
else:
print "eegRootDir has none."
print "EEG Root Dir is: ", eegRootDir
## LOAD IN BRAIN PLOTTING DATA
BRAINDIR = '../brain_plotting_code/'
brainMat = BRAINDIR + 'brain.mat'
roiMat = BRAINDIR + 'ROI.mat'
brain = scipy.io.loadmat(brainMat)
faces = brain['F']
vertices = brain['V']
print "Faces matrix: ", faces.shape
print "Vertices matrix: ", vertices.shape
roi = h5py.File(roiMat)
roi = roi['ROI']
roi = np.array(roi).T
print "ROI Matrix: ", roi.shape
In [39]:
## CONVERT DATA INTO DATAFRAMES
df_roi = pd.DataFrame(data=roi,
index=[range(0, len(roi))],
columns=['x', 'y', 'z'])
df_vertices = pd.DataFrame(data=vertices,
index=[range(0, len(vertices))],
columns=['x', 'y', 'z'])
df_faces = pd.DataFrame(data=faces,
index=[range(0, len(faces))],
columns=['v1', 'v2', 'v3'])
print df_vertices.shape
print df_faces.shape
print df_roi.shape
display(df_roi.head())
display(df_vertices.head())
display(df_faces.head())
## SAVE TO JSON/CSV, comment 1 out
OUTPUT_ROI = 'data/roi.csv'
OUTPUT_V = 'data/vertices.csv'
OUTPUT_F = 'data/faces.csv'
# save the dataframe
df_roi.to_csv(OUTPUT_ROI)
df_vertices.to_csv(OUTPUT_V)
df_faces.to_csv(OUTPUT_F)
OUTPUT_ROI = 'data/roi.json'
OUTPUT_V = 'data/vertices.json'
OUTPUT_F = 'data/faces.json'
df_roi.to_json(OUTPUT_ROI)
df_vertices.to_json(OUTPUT_V)
df_faces.to_json(OUTPUT_F)
In [ ]: